package multithreading;

import java.util.concurrent.*;

public class CallAbleDemo implements Callable<String> {
    @Override
    public String call() throws Exception {
        return Thread.currentThread().getName();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallAbleDemo demo = new CallAbleDemo();
        //创建一个固定线程的线程池
        ExecutorService es = Executors.newFixedThreadPool(3);
        //执行线程
        Future<String> s1 = es.submit(demo);
        Future<String> s2 = es.submit(demo);
        Future<String> s3 = es.submit(demo);
        //获取结果
        System.out.println(s1.get());
        System.out.println(s2.get());
        System.out.println(s3.get());
        //关闭线程池
        es.shutdownNow();

    }
}
